package com.jungle.bfi.controller;

import com.jungle.base.dao.SpecBuilder;
import com.jungle.base.domain.bo.BaseUserBo;
import com.jungle.base.domain.vo.JsonResult;
import com.jungle.bfi.domain.bo.DatasetItemBo;
import com.jungle.bfi.entity.DatasetItemPo;
import com.jungle.bfi.service.metadata.DatasetItemService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("datasetItem")
public class DatasetItemController {
    @Resource
    private DatasetItemService datasetItemService;
    @PostMapping("store")
    public JsonResult<DatasetItemPo> store(@RequestBody DatasetItemBo qo) {
        DatasetItemPo dataItemPo = datasetItemService.saveOrUpdate(qo, new BaseUserBo());
        return JsonResult.success(dataItemPo);
    }

    @PostMapping("list")
    public JsonResult<List<DatasetItemPo>> list(@RequestBody DatasetItemBo bo) {
        List<DatasetItemPo> list = datasetItemService.findAll(new SpecBuilder<DatasetItemPo>(bo).toSpec());
        return JsonResult.success(list);
    }
}
